// pages/member/evaluate/index.js
import {list,addTo,del} from "../../../api/orderReview"
let app = getApp();
import util from '../../../utils/util'
Page({

    /**
     * 页面的初始数据
     */
    data: {
      name:'',
      header:'',
      total:0,
      id:'',
      delid:'',
      list:[],
      pageNum:1,
      addTo:[],
      hiddenmodalput: true,
      conter:'',
      idx:''
    
  
    },
    display(data){
      this.data.conter=data.detail.value
    },
    loadList(){
      if(this.data.pageNum==1){
        this.data.list=[]
      }
      list().then(res=>{
        res.data.data.forEach(item=>{
          item.createDate=util.datetimeFormat(item.createDate)
          item.addToDate=util.datetimeFormat(item.addToDate)
          this.data.list.push(item)
        })
        this.data.total=res.data.total
        this.setData({
          total:this.data.total,
          list:this.data.list
        })
      })
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
      this.data.name=app.globalData.userInfo.nickName
      this.setData({
        name:this.data.name
      })
      this.loadList()
    },
    confirm(){
      console.log(this.data.idx)
     if(this.data.conter==''){
      wx.showToast({
        title: '请输入评价内容',
        duration: 2000,
        icon:'none'
      })
     }else{
      addTo({
        content:this.data.conter,
        orderReviewId:this.data.id
      }).then(res=>{
        if(res.type=='success'){
          wx.showToast({
            title: '成功',
            icon: 'success',
            duration: 2000
          })
          
          this.data.list[this.data.idx].addToReview=this.data.conter
          this.data.conter=''
          this.data.list[this.data.idx].addToDate=util.datetimeFormat(res.data.data.addToDate)
        
        }
        this.setData({
          conter:this.data.conter,
          list:this.data.list,
          hiddenmodalput:true
        })
      })
     }
    
    },
    evaluateClick(){
        wx.navigateTo({
            url: '/pages/member/evaluate/index',
          })
    },
    shareClick(){
        wx.navigateTo({
          url: '/pages/member/evaluate/share',
        })
      },

      deleteClick(e){
        var _this=this
        this.data.id=e.currentTarget.dataset.id
        this.data.idx=e.currentTarget.dataset.idx
        console.log(this.data.id);
        wx.showModal({
          content: '确定删除这条评价吗？',
          success (res) {
            if (res.confirm) {
              console.log('用户点击确定')
              del(
                _this.data.id
              ).then(res=>{
                if(res.type=='success'){
                  _this.data.list.splice(e.currentTarget.dataset.idx,1)
           _this.setData({
                    list:_this.data.list
                  })
                }
              })
            } else if (res.cancel) {
              console.log('用户点击取消')
            }
          }
        })
      },
      addevaluateClick (e) {
        // console.log(e)
      this.data.id=e.currentTarget.dataset.id
      this.data.idx=e.currentTarget.dataset.idx
      this.data.conter=''
        this.setData({
          conter:this.data.conter,
          hiddenmodalput: !this.data.hiddenmodalput
        })
      },
      
      jump(data){
        wx.navigateTo({
          url: '/pages/order/order/details?id=' + data.currentTarget.dataset.id,
        })
      }
     
})